package com.hmkj.admin.controller.user;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hmkj.admin.controller.BaseController;
import com.hmkj.admin.controller.GenericController;
import com.hmkj.admin.utils.AdminSessionHelper;
import com.hmkj.common.entity.dtgrid.DtGrid;
import com.hmkj.core.constant.Enum;
import com.hmkj.core.exception.DtGridException;
import com.hmkj.core.po.system.Admin;
import com.hmkj.core.po.user.User;
import com.hmkj.core.po.userBank.UserBank;
import com.hmkj.core.service.user.UserService;
import com.hmkj.core.service.userBank.UserBankService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Controller
@RequestMapping(BaseController.BASE_URI)
public class UserBankJsonController extends GenericController<Integer, UserBank> {
    @Resource
    private UserService userService;
    @Resource
    private UserBankService userBankService;

    /**
     * 银行卡json列表
     *
     * @param dtGridPager
     * @return
     * @throws DtGridException
     */
    @RequiresPermissions("sys:bind:list")
    @RequestMapping(value = "bind/list.json", method = RequestMethod.POST)
    @ResponseBody
    public DtGrid bankJsonList(String dtGridPager) throws Exception {
        dtGridPager = dataAuthority(dtGridPager);
        return userBankService.getDtGridList(dtGridPager, UserBank.class);
    }

//    /**
//     * 银行卡认证列表json数据
//     */
//    @ResponseBody
//    @RequestMapping("userBank/json/list")
//    @RequiresPermissions("sys:user:bank:list")
//    public DtGrid listJson(String dtGridPager) throws Exception {
//        DtGrid dtgrid = dataAuthority(dtGridPager, Constants.AG);
//        return userBankService.getDtGridList(dtgrid, UserBankModel.class);
//    }
//
//    /**
//     * 修改
//     */
//    @ResponseBody
//    @RequestMapping(value = "/userBank/json/edit")
//    @RequiresPermissions("sys:user:bank:edit")
//    public ResultEntity edit(UserBank userBank) throws Exception {
//        UserBank oldUserBank = userBankService.selectOne(new UserBank(u -> {
//            u.setId(userBank.getId());
//            u.setDelFlag(UserBank.DELFLAG.NORMAL.code);
//        }));
//        if (null == oldUserBank) {
//            throw new BussinessException("该银行卡信息不存在");
//        }
//        if(userBank.getBankCode().length()>20){
//            throw new BussinessException("银行卡号超过20个字符");
//        }
//        if(!ValidateUtils.isNumeric(userBank.getBankCode())){
//            throw new BussinessException("银行卡号格式有误");
//        }
//        String str  = "^[\\u4e00-\\u9fa5]+$";
//        if(!userBank.getBranch().matches(str)){
//            throw new BussinessException("支行名称必须中文");
//        }
//        Bank bank =bankService.selectOne(new Bank(t->t.setInsideCode(userBank.getBankCode())));
//        userBankService.updateByPrimaryKeySelective(new UserBank(u -> {
//            u.setId(oldUserBank.getId());
//            u.setBankNo(userBank.getBankNo());
//            u.setBankName(bank.getName());
//            u.setBankCode(userBank.getBankCode());
//            u.setBranch(userBank.getBranch());
//        }));
//        return ok();
//    }
//
//    /**
//     * 审核
//     */
//    @ResponseBody
//    @RequestMapping(value = "/userBank/json/refuse")
//    @RequiresPermissions("sys:bind:audit")
//    public ResultEntity refuse(UserBank userBank) throws Exception {
//        UserBank oldUserBank = userBankService.selectOne(new UserBank(u -> {
//            u.setId(userBank.getId());
//            u.setDelFlag(UserBank.DELFLAG.NORMAL.code);
//        }));
//        if (null == oldUserBank) {
//            throw new BussinessException("该银行卡信息不存在");
//        } else if (oldUserBank.getStatus() != UserBank.STATUS.T1.code) {
//            throw new BussinessException("当前状态下不能操作");
//        }
//        userBankService.updateByPrimaryKeySelective(new UserBank(u -> {
//            u.setId(oldUserBank.getId());
//            u.setStatus(userBank.getStatus());
//            u.setRemark(userBank.getRemark());
//        }));
//        return ok();
//    }
//
//    /**
//     * 列表导出
//     *
//     * @param dtGridPager
//     * @return
//     */
//    @ResponseBody
//    @RequestMapping(value = "userBank/json/export", method = RequestMethod.POST)
//    public ResultEntity export(String dtGridPager, HttpServletRequest request, HttpServletResponse response) throws Exception {
//        // 执行导出
//        ExportUtils.export(request, response, userBankService.getDtGridListExport(dtGridPager, UserBankModel.class));
//        return ok();
//    }
}
